package com.ruoyi.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysDictInfo;
import com.ruoyi.system.service.ISysDictInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 字典信息Controller
 * 
 * @author ruoyi
 * @date 2022-02-12
 */
@RestController
@RequestMapping("/system/info")
public class SysDictInfoController extends BaseController
{
    @Autowired
    private ISysDictInfoService sysDictInfoService;

    /**
     * 查询字典信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysDictInfo sysDictInfo)
    {
        startPage();
        List<SysDictInfo> list = sysDictInfoService.selectSysDictInfoList(sysDictInfo);
        return getDataTable(list);
    }

    /**
     * 导出字典信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:export')")
    @Log(title = "字典信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysDictInfo sysDictInfo)
    {
        List<SysDictInfo> list = sysDictInfoService.selectSysDictInfoList(sysDictInfo);
        ExcelUtil<SysDictInfo> util = new ExcelUtil<SysDictInfo>(SysDictInfo.class);
        return util.exportExcel(list, "info");
    }

    /**
     * 获取字典信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:query')")
    @GetMapping(value = "/{recNo}")
    public AjaxResult getInfo(@PathVariable("recNo") String recNo)
    {
        return AjaxResult.success(sysDictInfoService.selectSysDictInfoById(recNo));
    }

    /**
     * 新增字典信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:add')")
    @Log(title = "字典信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysDictInfo sysDictInfo)
    {
        return toAjax(sysDictInfoService.insertSysDictInfo(sysDictInfo));
    }

    /**
     * 修改字典信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:edit')")
    @Log(title = "字典信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysDictInfo sysDictInfo)
    {
        return toAjax(sysDictInfoService.updateSysDictInfo(sysDictInfo));
    }

    /**
     * 删除字典信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:remove')")
    @Log(title = "字典信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recNos}")
    public AjaxResult remove(@PathVariable String[] recNos)
    {
        return toAjax(sysDictInfoService.deleteSysDictInfoByIds(recNos));
    }
}
